package com.shanjupay.merchant.service;

import com.shanjupay.merchant.convert.MerchantConvert;
import com.shanjupay.merchant.entity.Merchant;
import com.shanjupay.merchant.mapper.MerchantMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import shanjupay.merchant.Dto.MerchantDTO;
import shanjupay.merchant.api.MerchantService;

@Service
public class MerchantServiceImpl implements MerchantService {
    @Autowired
    MerchantMapper merchantMapper;

    /**
     * 根据ID查询详细信息
     *
     * @param merchantId
     * @return
     * @throws]
     */
    @Override
    public MerchantDTO queryMerchantById(Long merchantId) {
        Merchant merchant = merchantMapper.selectById(merchantId);
        MerchantDTO merchantDTO = new MerchantDTO();
        merchantDTO.setId(merchant.getId());
        //设置其它属性...
        return merchantDTO;
    }

    /**
     * 商户注册
     *
     * @param merchantDTO
     * @return
     */
    @Override
    public MerchantDTO createMerchant(MerchantDTO merchantDTO) {

//        Merchant merchant = new Merchant();
//        merchant.setMobile(merchantDTO.getMobile());

        //设置审核状态0‐未申请,1‐已申请待审核,2‐审核通过,3‐审核拒绝
        Merchant merchant = MerchantConvert.INSTANCE.MerchantDto2Merchant(merchantDTO);
        merchant.setAuditStatus("0");
        //保存商户
        merchantMapper.insert(merchant);
        //设置商户ID
        merchantDTO.setId(merchant.getId());
        return merchantDTO;
    }

}
